<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <title>进度条</title>
    <style>
        .wrapper {
            width: 400px;
            margin: 100px auto;
        }

        .progress {
            position: relative;
            width: 100%;
        }

        .progress-bg {
            height: 4px;
            border-radius: 4px;
            overflow: hidden;
            background-color: #eaecee;
            position: relative;
            z-index: 2;
        }

        .progress-bar {
            background: #15b7d4;
            width: 0;
            height: 4px;
            border-radius: 4px;
        }

        .progress-btn {
            width: 16px;
            height: 16px;
            border-radius: 50%;
            position: absolute;
            background: #fff;
            left: 0px;
            margin-left: -8px;
            top: -6px;
            cursor: pointer;
            border: 1px #15b7d4 solid;
            box-sizing: border-box;
            z-index: 3;
        }

        .progress-btn:before {
            position: absolute;
            width: 10px;
            height: 10px;
            content: "";
            top: 2px;
            left: 2px;
            display: block;
            border-radius: 50%;
            background: #15b7d4;
        }

        .progress-text {
            text-align: center;
            line-height: 30px;
            color: #333333;
            font-size: 14px;
        }

        .progress-text::selection {
            color: #333333;
            background-color: none;
        }

        .progress-text::-moz-selection {
            color: #333333;
            background-color: none;
        }

        .progress-text::-webkit-selection {
            color: #333333;
            background-color: none;
        }

        .progress-step {
            position: absolute;
            top: -3px;
            left: -3px;
            display: flex;
            justify-content: space-between;
            width: calc(100% + 6px);
            z-index: 2;
            -webkit-padding-start: 0px;
            -webkit-margin-before: 0;
            -webkit-margin-after: 0;
        }

        .progress-step li {
            list-style: none;
            width: 10px;
            height: 10px;
            background-color: #eaecee;
            border-radius: 50%;
        }
        .blue-step li.on{background: #15b7d4;}
        .blue-bar,.blue-btn:before{
            background: #15b7d4;
        }
        .blue-btn {
            border-color: #15b7d4;
        }
        .red-step li.on{background: #e16161;}
        .red-bar,.red-btn:before{
            background: #e16161;
        }
        .red-btn {
            border-color: #e16161;
        }
    </style>
</head>

<body>
    <div class="wrapper">
        <div class="progress">
            <div class="progress-bg">
                <div class="progress-bar blue-bar"></div>
            </div>
            <div class="progress-btn blue-btn"></div>
            <div class="progress-text">0%</div>
            <ul class="progress-step blue-step">
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
    </div>
    <div class="wrapper">
        <div class="progress">
            <div class="progress-bg">
                <div class="progress-bar red-bar"></div>
            </div>
            <div class="progress-btn red-btn"></div>
            <div class="progress-text">0%</div>
            <ul class="progress-step red-step">
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
    </div>


    <script>
        $('.wrapper').each(function(){
            var _this=$(this);
            var tag = false, ox = 0, left = 0, bgleft = 0;
            var allW = _this.width();
            _this.find('.progress-btn').mousedown(function (e) {
                ox = e.pageX - left;
                tag = true;
            });
            $(document).mouseup(function () {
                tag = false;
            });
            _this.find('.progress').mousemove(function (e) {//鼠标移动
                if (tag) {
                    left = e.pageX - ox;
                    if (left <= 0) {
                        left = 0;
                    } else if (left > allW) {
                        left = allW;
                    }
                    _this.find('.progress-btn').css('left', left);
                    _this.find('.progress-bar').width(left);
                    _this.find('.progress-text').html(parseInt((left / allW) * 100) + '%');
                    var stepIndex=Math.floor(left/allW*10/2.5);
                    _this.find('.progress-step li').eq(stepIndex+1).prevAll().addClass('on');
                    _this.find('.progress-step li').eq(stepIndex).nextAll().removeClass('on');
                    
                }
            });
        })
    </script>
</body>

</html>